import { ApiProperty } from '@nestjs/swagger';
import { IsUrl, IsNotEmpty, ValidateIf } from 'class-validator';

export class CreateWorkDto {
  @ApiProperty({ description: '封面图片地址' })
  @IsNotEmpty({ message: '封面图片地址必填' })
  @IsUrl()
  imgUrl: string;

  @ApiProperty({ description: '项目名' })
  @IsNotEmpty({ message: '项目名必填' })
  name: string;

  @ApiProperty({ description: '描述' })
  @IsNotEmpty({ message: '描述必填' })
  desc: string;

  @ApiProperty({ description: '优先级' })
  priority?: number = 0;

  @ApiProperty({ description: '访问链接' })
  @ValidateIf((o) => o.sourceUrl !== '')
  @IsUrl()
  linkUrl?: string;

  @ApiProperty({ description: '源码链接' })
  @ValidateIf((o) => o.sourceUrl !== '')
  @IsUrl()
  sourceUrl?: string;
}
